************************************
* Table Dif-in-Dif Intensity
************************************

 clear all
 set more off
 use "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 50 Terremotos\DataN\BaseProyecto.dta"
 keep if ano==2017 | ano==2018
 rename Clave clave
 sort clave


 merge clave using "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 50 Terremotos\DataN\Intensidad.dta"
 
 replace magnitud1 = 0 if _merge==1
 replace magnitud1 = 8 if clave==20066
 gen Intensidad = Terremoto*magnitud1
 
 rename clave Clave
 label var Intensidad "Intensity"


summarize Intensidad if Terremoto==1 [aw=pob]
return list
local intn =  r(mean)
local rint = round(`intn', 0.001)
/*
 sum Intensidad [aw=pob]
 return list
 local iag =  r(mean)
 local iavg = round(`iag', 0.01)

 
 gen Terremoto= After*earthquake
 tab Terremoto
 
 sum IPVt   sexabuset violaciont 
 
 gen lIPVt=log(1+IPVt)
 gen lsexabuset=log(1+sexabuset)
 gen lviolaciont=log(1+violaciont)
 
 sum lIPVt   lsexabuset lviolaciont 
 
 label var Terremoto "Earthquake"
 label var lIPVt "Domestic Violence"
 label var lsexabuset "Sexual Abuse"
 label var lviolaciont "Rape"
 */
 
 local pathdata2 "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 50 Terremotos\OutputN"
cd "`pathdata2'"
/*
  sum lAmenazast lLesionest lHomicidiost lRoboVeht lRoboCasat lDanoPropt 
 
 foreach var of varlist lAmenazast lLesionest lHomicidiost lRoboVeht lRoboCasat lDanoPropt   {
 	qui reghdfe `var' Terremoto i.mes i.ano  [aw=pob], absorb(i.Clave) cluster(Clave)
est store D`var'
}
 
 esttab DlAmenazast DlLesionest DlHomicidiost DlRoboVeht DlRoboCasat DlDanoPropt ///
 using  "Tabla2A.tex", ///
 b(3) se(3) se label star(* 0.1 ** 0.05 *** 0.01) ///
 title(Difference-in-Differences Specification:   \label{lpmpsycho}) ///
 nomtitles r2(2) obslast 
 
 */
 
 
   global dep Amenazast Lesionest RoboVeht RoboCasat DanoPropt

 
	 foreach var in $dep {
		eststo l`var': reghdfe  l`var' Intensidad i.mes i.ano [aw=pob], absorb( i.Clave) cluster(Clave)
		estadd local fe "X" : l`var'  
		foreach i in 0 1 {
			sum  Intensidad  [aw=pob] if Terremoto==`i'
			local  m`i' : di %9.2fc r(mean)  
			estadd local m`i'   "`m`i''" : l`var' 
		}
	 }
	  
	global label "\shortstack{Rates Per\\100,000 Inh.:}"
	global mgroups " "\shortstack{Assault}"  "\shortstack{Aggravated\\Assault}" "\shortstack{Vehicle\\Theft}" "\shortstack{Residential\\Burglary}" "\shortstack{Vandalism}" "  
	global pattern "1 1 1 1 1 1"
	esttab lAmenazast lLesionest lRoboVeht lRoboCasat lDanoPropt using "Intensidad.tex" , replace  se  /*
					*/ noconstant  lines 	f	compress    /*
					*/ mlabels(none)   	 /*   
					*/ label 	booktabs  b(%9.3fc) se(%9.3fc) /*
					*/ alignment(C C)   star(* 0.10 ** 0.05 *** 0.01) /*
					*/ keep( *Intensidad* )     /*
					*/ nobaselevels   /*
					*/ stats(r2 N g m1 fe        ,  /*
					*/ labels("\(R^{2}\)" "Observations" "  \midrule \vspace{-4mm}" "Mean Intensity"  /*
					*/ "Baseline FE"    )  /*
					*/	 fmt(%9.2fc %9.0fc %9.3fc  %9.2fc  %9.3fc )  )    /*
					*/ mgroups( $mgroups , lhs("\textsc{${label}}") /*
					*/ pattern( $pattern ) span  /*
					*/ prefix(\multicolumn{@span}{c}{) suffix(})   erepeat(\cmidrule(lr){@span}))
					
/*
 
 reghdfe feminicidiot Intensidad i.mes i.ano [aw=pob], absorb( i.clave) cluster(clave)
 est store A
 estadd local IntensityEQ1 `rint' , replace
 *estadd local IntensityAvg 0`iavg'03 , replace

 reghdfe lsexabuset Intensidad i.mes i.ano [aw=pob], absorb( i.clave) cluster(clave)
 est store B
 estadd local IntensityEQ1 `rint' , replace
 *estadd local IntensityAvg 0`iavg'03 , replace

 reghdfe lviolaciont Intensidad i.mes i.ano [aw=pob], absorb( i.clave) cluster(clave)
 est store C
 estadd local IntensityEQ1 `rint' , replace
 *estadd local IntensityAvg 0`iavg'03 , replace

 
 esttab A B C   ///
 using  "Intensidad.tex", replace ///
 keep(Intensidad) ///
 b(3) se(3) se label star(* 0.1 ** 0.05 *** 0.01) ///
 title(OLS Estimates:   \label{lpmpsycho}) ///
 stats(N r2 IntensityEQ1, fmt(0 2 2 2))
 */
 
 *Intensity 4+*
 g strong1 = Intensidad >= 4
 label var strong1 "Intensity>=4"

 
*/

	 foreach var in $dep {
		eststo l`var': reghdfe  l`var' strong1 i.mes i.ano [aw=pob], absorb( i.Clave) cluster(Clave)
		estadd local fe "X" : l`var'  
		foreach i in 0 1 {
			sum  `var'  [aw=pob] if strong1==`i'  & earthquake==1
			local  m`i' : di %9.2fc r(mean)  
			estadd local m`i'   "`m`i''" : l`var' 
		}
	 }
	  
	global label "\shortstack{Rates Per\\100,000 Inh.:}"
	global mgroups " "\shortstack{Assault}"  "\shortstack{Aggravated\\Assault}" "\shortstack{Vehicle\\Theft}" "\shortstack{Residential\\Burglary}" "\shortstack{Vandalism}" "  
	global pattern "1 1 1 1 1 1"
	esttab lAmenazast lLesionest lRoboVeht lRoboCasat lDanoPropt using "Intensidad_4.tex" , replace  se  /*
					*/ noconstant  lines 	f	compress    /*
					*/ mlabels(none)   	 /*   
					*/ label 	booktabs  b(%9.3fc) se(%9.3fc) /*
					*/ alignment(C C)   star(* 0.10 ** 0.05 *** 0.01) /*
					*/ keep( *strong* )     /*
					*/ nobaselevels   /*
					*/ stats(r2 N g  fe        ,  /*
					*/ labels("\(R^{2}\)" "Observations" "  \midrule \vspace{-4mm}" /*
					*/ "Baseline FE"    )  /*
					*/	 fmt(%9.2fc %9.0fc %9.3fc  %9.3fc )  )    /*
					*/ mgroups( $mgroups , lhs("\textsc{${label}}") /*
					*/ pattern( $pattern ) span  /*
					*/ prefix(\multicolumn{@span}{c}{) suffix(})   erepeat(\cmidrule(lr){@span}))

					
 *Intensity 5+*			
 g strong2 = Intensidad >= 5
 label var strong2 "Intensity>=5"

 
*/

	 foreach var in $dep {
		eststo l`var': reghdfe  l`var' strong2 i.mes i.ano [aw=pob], absorb( i.Clave) cluster(Clave)
		estadd local fe "X" : l`var'  
		foreach i in 0 1 {
			sum  `var'  [aw=pob] if strong2==`i'  & earthquake==1
			local  m`i' : di %9.2fc r(mean)  
			estadd local m`i'   "`m`i''" : l`var' 
		}
	 }
	  
	global label "\shortstack{Rates Per\\100,000 Inh.:}"
	global mgroups " "\shortstack{Assault}"  "\shortstack{Aggravated\\Assault}" "\shortstack{Vehicle\\Theft}" "\shortstack{Residential\\Burglary}" "\shortstack{Vandalism}" "  
	global pattern "1 1 1 1 1 1"
	esttab lAmenazast lLesionest lRoboVeht lRoboCasat lDanoPropt using "Intensidad_5.tex" , replace  se  /*
					*/ noconstant  lines 	f	compress    /*
					*/ mlabels(none)   	 /*   
					*/ label 	booktabs  b(%9.3fc) se(%9.3fc) /*
					*/ alignment(C C)   star(* 0.10 ** 0.05 *** 0.01) /*
					*/ keep( *strong* )     /*
					*/ nobaselevels   /*
					*/ stats(r2 N g fe        ,  /*
					*/ labels("\(R^{2}\)" "Observations" "  \midrule \vspace{-4mm}"  /*
					*/ "Baseline FE"    )  /*
					*/	 fmt(%9.2fc %9.0fc %9.3fc  %9.3fc )  )    /*
					*/ mgroups( $mgroups , lhs("\textsc{${label}}") /*
					*/ pattern( $pattern ) span  /*
					*/ prefix(\multicolumn{@span}{c}{) suffix(})   erepeat(\cmidrule(lr){@span}))
					

 *Intensity 6+*			
 g strong3 = Intensidad >= 6
 label var strong3 "Intensity>=6"

 
*/

	 foreach var in $dep {
		eststo l`var': reghdfe  l`var' strong3 i.mes i.ano [aw=pob], absorb( i.Clave) cluster(Clave)
		estadd local fe "X" : l`var'  
		foreach i in 0 1 {
			sum  `var'  [aw=pob] if strong3==`i'  & earthquake==1
			local  m`i' : di %9.2fc r(mean)  
			estadd local m`i'   "`m`i''" : l`var' 
		}
	 }
	  
	global label "\shortstack{Rates Per\\100,000 Inh.:}"
	global mgroups " "\shortstack{Assault}"  "\shortstack{Aggravated\\Assault}" "\shortstack{Vehicle\\Theft}" "\shortstack{Residential\\Burglary}" "\shortstack{Vandalism}" "  
	global pattern "1 1 1 1 1 1"
	esttab lAmenazast lLesionest lRoboVeht lRoboCasat lDanoPropt using "Intensidad_6.tex" , replace  se  /*
					*/ noconstant  lines 	f	compress    /*
					*/ mlabels(none)   	 /*   
					*/ label 	booktabs  b(%9.3fc) se(%9.3fc) /*
					*/ alignment(C C)   star(* 0.10 ** 0.05 *** 0.01) /*
					*/ keep( *strong* )     /*
					*/ nobaselevels   /*
					*/ stats(r2 N g fe        ,  /*
					*/ labels("\(R^{2}\)" "Observations" "  \midrule \vspace{-4mm}"  /*
					*/ "Baseline FE"    )  /*
					*/	 fmt(%9.2fc %9.0fc %9.3fc  %9.3fc )  )    /*
					*/ mgroups( $mgroups , lhs("\textsc{${label}}") /*
					*/ pattern( $pattern ) span  /*
					*/ prefix(\multicolumn{@span}{c}{) suffix(})   erepeat(\cmidrule(lr){@span}))
		
		
 *Intensity 7+*			
 g strong4 = Intensidad >= 7
 label var strong4 "Intensity>=7"

 
*/

	 foreach var in $dep {
		eststo l`var': reghdfe  l`var' strong4 i.mes i.ano [aw=pob], absorb( i.Clave) cluster(Clave)
		estadd local fe "X" : l`var'  
		foreach i in 0 1 {
			sum  `var'  [aw=pob] if strong4==`i'  & earthquake==1
			local  m`i' : di %9.2fc r(mean)  
			estadd local m`i'   "`m`i''" : l`var' 
		}
	 }
	  
	global label "\shortstack{Rates Per\\100,000 Inh.:}"
	global mgroups " "\shortstack{Assault}"  "\shortstack{Aggravated\\Assault}" "\shortstack{Vehicle\\Theft}" "\shortstack{Residential\\Burglary}" "\shortstack{Vandalism}" "  
	global pattern "1 1 1 1 1 1"
	esttab lAmenazast lLesionest lRoboVeht lRoboCasat lDanoPropt using "Intensidad_7.tex" , replace  se  /*
					*/ noconstant  lines 	f	compress    /*
					*/ mlabels(none)   	 /*   
					*/ label 	booktabs  b(%9.3fc) se(%9.3fc) /*
					*/ alignment(C C)   star(* 0.10 ** 0.05 *** 0.01) /*
					*/ keep( *strong* )     /*
					*/ nobaselevels   /*
					*/ stats(r2 N g fe        ,  /*
					*/ labels("\(R^{2}\)" "Observations" "  \midrule \vspace{-4mm}"  /*
					*/ "Baseline FE"    )  /*
					*/	 fmt(%9.2fc %9.0fc %9.3fc  %9.3fc )  )    /*
					*/ mgroups( $mgroups , lhs("\textsc{${label}}") /*
					*/ pattern( $pattern ) span  /*
					*/ prefix(\multicolumn{@span}{c}{) suffix(})   erepeat(\cmidrule(lr){@span}))
